package com.example.administrator.yanfoxconn.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.GridLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.yanfoxconn.R;
import com.example.administrator.yanfoxconn.adapter.SanFangListAdapter;
import com.example.administrator.yanfoxconn.bean.ActivityMsg;
import com.example.administrator.yanfoxconn.bean.ExcePhoto;
import com.example.administrator.yanfoxconn.bean.SelectModel;
import com.example.administrator.yanfoxconn.constant.Constants;
import com.example.administrator.yanfoxconn.constant.FoxContext;
import com.example.administrator.yanfoxconn.constant.ImageCaptureManager;
import com.example.administrator.yanfoxconn.intent.PhotoPickerIntent;
import com.example.administrator.yanfoxconn.intent.PhotoPreviewIntent;
import com.example.administrator.yanfoxconn.utils.BaseActivity;
import com.example.administrator.yanfoxconn.utils.DateTimePickDialogUtil;
import com.example.administrator.yanfoxconn.utils.FileUtil;
import com.example.administrator.yanfoxconn.utils.HttpConnectionUtil;
import com.example.administrator.yanfoxconn.utils.ImageZipUtils;
import com.example.administrator.yanfoxconn.utils.ToastUtils;
import com.example.administrator.yanfoxconn.widget.MyListView;
import com.example.administrator.yanfoxconn.widget.TouchImageView;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import org.json.JSONArray;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 人資活動    歷史詳情
 * Created by S1007989 on 2021/5/18.
 */

public class ActHistoryDetialActivity extends BaseActivity implements View.OnClickListener{
    @BindView(R.id.btn_title_left)
    Button btnBack;//返回
    @BindView(R.id.tv_title)
    TextView tvTittle;//標題
    @BindView(R.id.btn_title_right)
    Button btnUp;//結束/提交

    @BindView(R.id.rb_person)
    RadioButton rbPerson;//個人
    @BindView(R.id.rb_team)
    RadioButton rbTeam;//團隊
    @BindView(R.id.et_act_name)
    EditText etActName;//活動名稱
    @BindView(R.id.et_act_rules)
    EditText etActRules;//活動規則
    @BindView(R.id.et_act_award)
    EditText etActAward;//獎品設置
    @BindView(R.id.tv_time_start)
    TextView tvStartTime;//活動開始時間
    @BindView(R.id.tv_end_sign)
    TextView tvEndSignDate;//報名截止時間
    @BindView(R.id.tr_team_num)
    TableRow trTeamNum;//隊伍上限數量TableRow顯示隱藏
    @BindView(R.id.et_num_team)
    EditText etNumTeam;//隊伍上限數量
    @BindView(R.id.et_num_person)
    EditText etNumPerson;//活動上限人數

    @BindView(R.id.tl_end)
    TableLayout tlEnd;//結束信息TableLayout
    @BindView(R.id.ll_photo)
    LinearLayout llPhoto;//結束信息圖片LinearLayout
    @BindView(R.id.tv_time_end)
    TextView tvEndTime;//活動結束時間
    @BindView(R.id.et_num_now)
    EditText etNumNow;//現場活動人數

    @BindView(R.id.tv_sign_now)
    TextView tvSignNow;//已報人數/隊伍
    @BindView(R.id.tv_num_person)
    TextView tvNumPerson;//活動上限人數TV

    @BindView(R.id.et_code)
    TextView tvCode;//冠軍工號
    @BindView(R.id.tv_name)
    TextView tvName;//冠軍姓名
    @BindView(R.id.et_score)
    TextView tvScore;//冠軍得分

    @BindView(R.id.et_code2)
    TextView tvCode2;//亞軍工號
    @BindView(R.id.tv_name2)
    TextView tvName2;//亞軍姓名
    @BindView(R.id.et_score2)
    TextView tvScore2;//亞軍得分

    @BindView(R.id.gl1)
    GridLayout gl1;//圖片
    @BindView(R.id.gl2)
    GridLayout gl2;//圖片
    @BindView(R.id.gl3)
    GridLayout gl3;//圖片

    private String initStartDateTime; // 初始化开始时间
    private Date selectEndTime = null;//所選時間
    private Date curDate = null;//當前時間
    private String curDates;//當前時間
    private SimpleDateFormat formatter;
    private ActHistoryDetialActivity mContext = this;
    private boolean b = true;
    private String act_id; //活動ID
    private List<ActivityMsg> person1List;
    private List<ActivityMsg> person2List;
    private List<ExcePhoto> photo1List;
    private List<ExcePhoto> photo2List;
    private List<ExcePhoto> photo3List;

    private boolean isClicked = true;//判斷是否點擊
    private ActivityMsg activityMsg;
    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_act_history_detail);
        ButterKnife.bind(this);

        //getMessage();//根據工號獲得信息
        tvTittle.setText("活動詳情");
//        btnUp.setText("結束");
//        btnUp.setVisibility(View.VISIBLE);
//        btnUp.setOnClickListener(this);
        btnBack.setOnClickListener(this);
        //tvStartTime.setOnClickListener(this);
        //tvEndSignDate.setOnClickListener(this);
        //tvEndTime.setOnClickListener(this);
        tvSignNow.setOnClickListener(this);
        rbPerson.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    trTeamNum.setVisibility(View.GONE);
                }else{
                    trTeamNum.setVisibility(View.VISIBLE);
                }
            }
        });
        activityMsg = (ActivityMsg) getIntent().getSerializableExtra("item");
        if (activityMsg!=null){
            if (activityMsg.getAct_type().equals("個人賽")){
                rbPerson.setChecked(true);
                rbPerson.setEnabled(false);
                rbTeam.setEnabled(false);
                etNumPerson.setText(activityMsg.getAct_num_team());
            }else {
                rbTeam.setChecked(true);
                rbPerson.setEnabled(false);
                rbTeam.setEnabled(false);
                etNumTeam.setText(activityMsg.getAct_num_team());
                etNumPerson.setText(activityMsg.getAct_num_person());
                tvNumPerson.setText("單個隊伍人數");
            }
            etActName.setText(activityMsg.getAct_name());
            etActRules.setText(activityMsg.getAct_rules());
            etActAward.setText(activityMsg.getAct_award());
            tvStartTime.setText(activityMsg.getAct_time_start().substring(0,16));
            tvEndSignDate.setText(activityMsg.getAct_end_sign().substring(0,16));
            tvSignNow.setText(activityMsg.getAct_sign_now());
            etNumNow.setText(activityMsg.getAct_num_now());
            //tvSignNow.setBackgroundColor(getResources().getColor(R.color.color_7edbf4));
            tvSignNow.setBackgroundResource(R.color.color_74afdb);
            act_id = activityMsg.getAct_id();
            etActName.setEnabled(false);
            etActRules.setEnabled(false);
            etActAward.setEnabled(false);
            etNumPerson.setEnabled(false);
            etNumTeam.setEnabled(false);


        }


        //Log.e("-----activityMsg.getAct_id()-----", activityMsg.getAct_id() );
        formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        SimpleDateFormat formatterUse = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
        curDate = new Date(System.currentTimeMillis());
        //获取当前时间
        initStartDateTime = formatterUse.format(curDate);
        //tvStartTime.setText(formatter.format(curDate));
        //tvEndSignDate.setText(formatter.format(curDate));
        tvEndTime.setText(formatter.format(curDate));
        curDates = formatter.format(curDate);

        getMessage();


    }
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_title_left://返回
                finish();
                break;
            case R.id.btn_title_right://提交

                break;
            case R.id.tv_time_start:
                DateTimePickDialogUtil dateTimePicKDialog = new DateTimePickDialogUtil(
                        mContext, initStartDateTime);
                dateTimePicKDialog.dateTimePicKDialog(tvStartTime,"","");
                break;
            case R.id.tv_end_sign:
                DateTimePickDialogUtil dateTimePicKDialog2 = new DateTimePickDialogUtil(
                        mContext, initStartDateTime);
                dateTimePicKDialog2.dateTimePicKDialog(tvEndSignDate,"","");
                break;
            case R.id.tv_time_end:
                DateTimePickDialogUtil dateTimePicKDialog3 = new DateTimePickDialogUtil(
                        mContext, initStartDateTime);
                dateTimePicKDialog3.dateTimePicKDialog(tvEndTime,"","");
                break;
            case R.id.tv_sign_now:
                Intent intent4 = new Intent(mContext,ActBaoMingListActivity.class);
                intent4.putExtra("act_id",activityMsg.getAct_id());
                startActivity(intent4);
                break;

        }
    }

    //獲取歷史詳情
    private void getMessage() {
        if (FoxContext.getInstance().getLoginId().equals("")) {
            ToastUtils.showShort(this, "登錄超時,請重新登陸");
            return;
        }
        final String url = Constants.HTTP_ACTIVITY_JSON_SERVLET; //此處寫上自己的URL

        JsonObject object = new JsonObject();
        object.addProperty("flag","getHistoryDetail");
        object.addProperty("act_id",act_id);

        Log.e("-----object------",  object.toString());

        //開啟一個新執行緒，向伺服器上傳資料
        new Thread() {
            public void run() {
                //把网络访问的代码放在这里
                try {
                    showDialog();
                    Log.e("---------", "==fff===" + url);
                    String result = HttpConnectionUtil.doPostJsonObject(url, object);
                    dismissDialog();
                    Gson gson = new Gson();
                    if (result != null) {
                        Log.e("---------", "result==fff===" + result);
                        JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
                        String errCode = jsonObject.get("errCode").getAsString();
                        if (errCode.equals("200")) {

                            JsonObject jsonObject2 = jsonObject.get("result").getAsJsonObject();

                            JsonArray array1 = jsonObject2.get("photo1").getAsJsonArray();
                            JsonArray array2 = jsonObject2.get("photo2").getAsJsonArray();
                            JsonArray array3 = jsonObject2.get("photo3").getAsJsonArray();

                            JsonArray array_1 = jsonObject2.get("result1").getAsJsonArray();
                            JsonArray array_2 = jsonObject2.get("result2").getAsJsonArray();

                            person1List = new ArrayList<ActivityMsg>();
                            person2List = new ArrayList<ActivityMsg>();

                            photo1List = new ArrayList<ExcePhoto>();
                            photo2List = new ArrayList<ExcePhoto>();
                            photo3List = new ArrayList<ExcePhoto>();

                            for (JsonElement type : array1) {
                                ExcePhoto humi = gson.fromJson(type, ExcePhoto.class);
                                photo1List.add(humi);
                            }
                            for (JsonElement type : array2) {
                                ExcePhoto humi = gson.fromJson(type, ExcePhoto.class);
                                photo2List.add(humi);
                            }
                            for (JsonElement type : array3) {
                                ExcePhoto humi = gson.fromJson(type, ExcePhoto.class);
                                photo3List.add(humi);
                            }
                            for (JsonElement type : array_1) {
                                ActivityMsg humi = gson.fromJson(type, ActivityMsg.class);
                                person1List.add(humi);
                            }
                            for (JsonElement type : array_2) {
                                ActivityMsg humi = gson.fromJson(type, ActivityMsg.class);
                                person2List.add(humi);
                            }

                            Message message = new Message();
                            message.what = Constants.MESSAGE_SET_TEXT;
                            message.obj = jsonObject.get("errMessage").getAsString();
                            mHandler.sendMessage(message);

                        } else{
                            Message message = new Message();
                            message.what = Constants.MESSAGE_TOAST;
                            message.obj = jsonObject.get("errMessage").getAsString();
                            mHandler.sendMessage(message);
                        }
                    }else{
                        Message message = new Message();
                        message.what = Constants.MESSAGE_NETMISTAKE;
                        mHandler.sendMessage(message);
                        finish();
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        }.start();
    }


    Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {

                case Constants.MESSAGE_TOAST://Toast彈出

                   ToastUtils.showLong(ActHistoryDetialActivity.this, msg.obj.toString());
//                    finish();
                    break;
                case Constants.MESSAGE_SET_TEXT://text賦值
                    setText();
//                    aboutAlert(msg.obj.toString(),MESSAGE_SET_TEXT);
                    break;
                case Constants.MESSAGE_UP://提交響應
                    worningAlert(msg.obj.toString(),Constants.MESSAGE_TOAST);
//                    ToastUtils.showLong(CrossScanActivity.this, msg.obj.toString());

                    break;
                case Constants.MESSAGE_ALERT://提交響應
                    worningAlert(msg.obj.toString(),Constants.MESSAGE_TOAST);
//                    ToastUtils.showLong(CrossScanActivity.this, msg.obj.toString());

                    break;
//                case MESSAGE_SHOW://顯示提醒
//                    setText();
//                    tvShow.setVisibility(View.VISIBLE);
//                    tvShow.setText(msg.obj.toString());
            }
            super.handleMessage(msg);
        }
    };

    private void setText() {
        if (person1List!=null && person1List.size()!=0) {
            tvCode.setText(person1List.get(0).getSign_code());
            tvName.setText(person1List.get(0).getSign_name());
            tvScore.setText(person1List.get(0).getScore());
        }
        if (person2List!=null && person2List.size()!=0) {
            tvCode2.setText(person2List.get(0).getSign_code());
            tvName2.setText(person2List.get(0).getSign_name());
            tvScore2.setText(person2List.get(0).getScore());
        }

        for (int i=0;i<photo1List.size();i++){
            TouchImageView imageView = new TouchImageView(ActHistoryDetialActivity.this);
//                        ImageView imageView = new ImageView(ZhiyinshuiExceDetailActivity.this);
            String imgStr = photo1List.get(i).getEXCE_FILENAME1();
            Log.e("------imgStr-----", "======"+imgStr);
            byte[] decode = Base64.decode(imgStr, Base64.DEFAULT);
            Bitmap bitmap = BitmapFactory.decodeByteArray(decode, 0, decode.length);
            imageView.setAdjustViewBounds(true);
            imageView.setScaleType(ImageView.ScaleType.CENTER);
            imageView.setImageBitmap(bitmap);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(200, 200);
            layoutParams.setMargins(10, 10, 10, 10);
            imageView.setLayoutParams(layoutParams);

            //設置點擊放大事件
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    int[] location = new int[2];
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        Rect frame = new Rect();
                        getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
                        int statusBarHeight = frame.top;

                        view.getLocationOnScreen(location);
                        location[1] += 0;
                    } else {
                        view.getLocationOnScreen(location);
                    }
                    view.invalidate();
                    int width = view.getWidth();
                    int height = view.getHeight();

                    Intent intent = new Intent(ActHistoryDetialActivity.this, BigImageActivity.class);
                    Bundle b = new Bundle();
                    b.putString(BigImageActivity.QR_IMAGE_URL, imgStr);
                    intent.putExtras(b);
//                                intent.putExtra(BigImageActivity.PHOTO_SELECT_POSITION,);
                    intent.putExtra(BigImageActivity.PHOTO_SELECT_X_TAG, location[0]);
                    intent.putExtra(BigImageActivity.PHOTO_SELECT_Y_TAG, location[1]);
                    intent.putExtra(BigImageActivity.PHOTO_SELECT_W_TAG, width);
                    intent.putExtra(BigImageActivity.PHOTO_SELECT_H_TAG, height);
                    startActivity(intent);
                    overridePendingTransition(0, 0);
                }
            });
            gl1.addView(imageView);
        }

        for (int i=0;i<photo2List.size();i++){
            TouchImageView imageView = new TouchImageView(ActHistoryDetialActivity.this);
//                        ImageView imageView = new ImageView(ZhiyinshuiExceDetailActivity.this);
            String imgStr = photo2List.get(i).getEXCE_FILENAME1();
            Log.e("------imgStr-----", "======"+imgStr);
            byte[] decode = Base64.decode(imgStr, Base64.DEFAULT);
            Bitmap bitmap = BitmapFactory.decodeByteArray(decode, 0, decode.length);
            imageView.setAdjustViewBounds(true);
            imageView.setScaleType(ImageView.ScaleType.CENTER);
            imageView.setImageBitmap(bitmap);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(200, 200);
            layoutParams.setMargins(10, 10, 10, 10);
            imageView.setLayoutParams(layoutParams);

            //設置點擊放大事件
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    int[] location = new int[2];
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        Rect frame = new Rect();
                        getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
                        int statusBarHeight = frame.top;

                        view.getLocationOnScreen(location);
                        location[1] += 0;
                    } else {
                        view.getLocationOnScreen(location);
                    }
                    view.invalidate();
                    int width = view.getWidth();
                    int height = view.getHeight();

                    Intent intent = new Intent(ActHistoryDetialActivity.this, BigImageActivity.class);
                    Bundle b = new Bundle();
                    b.putString(BigImageActivity.QR_IMAGE_URL, imgStr);
                    intent.putExtras(b);
//                                intent.putExtra(BigImageActivity.PHOTO_SELECT_POSITION,);
                    intent.putExtra(BigImageActivity.PHOTO_SELECT_X_TAG, location[0]);
                    intent.putExtra(BigImageActivity.PHOTO_SELECT_Y_TAG, location[1]);
                    intent.putExtra(BigImageActivity.PHOTO_SELECT_W_TAG, width);
                    intent.putExtra(BigImageActivity.PHOTO_SELECT_H_TAG, height);
                    startActivity(intent);
                    overridePendingTransition(0, 0);
                }
            });
            gl2.addView(imageView);
        }
        for (int i=0;i<photo3List.size();i++){
            TouchImageView imageView = new TouchImageView(ActHistoryDetialActivity.this);
//                        ImageView imageView = new ImageView(ZhiyinshuiExceDetailActivity.this);
            String imgStr = photo3List.get(i).getEXCE_FILENAME1();
            Log.e("------imgStr-----", "======"+imgStr);
            byte[] decode = Base64.decode(imgStr, Base64.DEFAULT);
            Bitmap bitmap = BitmapFactory.decodeByteArray(decode, 0, decode.length);
            imageView.setAdjustViewBounds(true);
            imageView.setScaleType(ImageView.ScaleType.CENTER);
            imageView.setImageBitmap(bitmap);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(200, 200);
            layoutParams.setMargins(10, 10, 10, 10);
            imageView.setLayoutParams(layoutParams);

            //設置點擊放大事件
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    int[] location = new int[2];
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        Rect frame = new Rect();
                        getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
                        int statusBarHeight = frame.top;

                        view.getLocationOnScreen(location);
                        location[1] += 0;
                    } else {
                        view.getLocationOnScreen(location);
                    }
                    view.invalidate();
                    int width = view.getWidth();
                    int height = view.getHeight();

                    Intent intent = new Intent(ActHistoryDetialActivity.this, BigImageActivity.class);
                    Bundle b = new Bundle();
                    b.putString(BigImageActivity.QR_IMAGE_URL, imgStr);
                    intent.putExtras(b);
//                                intent.putExtra(BigImageActivity.PHOTO_SELECT_POSITION,);
                    intent.putExtra(BigImageActivity.PHOTO_SELECT_X_TAG, location[0]);
                    intent.putExtra(BigImageActivity.PHOTO_SELECT_Y_TAG, location[1]);
                    intent.putExtra(BigImageActivity.PHOTO_SELECT_W_TAG, width);
                    intent.putExtra(BigImageActivity.PHOTO_SELECT_H_TAG, height);
                    startActivity(intent);
                    overridePendingTransition(0, 0);
                }
            });
            gl3.addView(imageView);
        }
    }




    private void aboutAlert(String msg, final int type) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("確認信息")
                .setMessage(msg)
                .setCancelable(false)
                .setPositiveButton("確認", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        // TODO Auto-generated method stub
                        if (type==Constants.MESSAGE_TOAST){
                            finish();
                        }else if(type==Constants.MESSAGE_UP){

                        }
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        // TODO Auto-generated method stub
//                        if (type==MESSAGE_TOAST){
//                            finish();
//                        }else if(type==MESSAGE_UP){
//                            check();
//                        }
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }
    private void worningAlert(String msg, final int t) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("提示信息")
                .setMessage(msg)
                .setCancelable(false)
                .setPositiveButton("確認", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        // TODO Auto-generated method stub
                        if (t==Constants.MESSAGE_TOAST) {
                            finish();
                        }
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }

    private class GridAdapter extends BaseAdapter {
        private ArrayList<String> listUrls;

        public GridAdapter(ArrayList<String> listUrls) {
            this.listUrls = listUrls;
        }

        @Override
        public int getCount() {
            if (listUrls.size() == 1) {
                return 1;
            } else {
                return listUrls.size() + 1;
            }

        }

        @Override
        public String getItem(int position) {
            return listUrls.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView;
            if (convertView == null) {
                convertView = getLayoutInflater().inflate(R.layout.item_image, null);
                imageView = (ImageView) convertView.findViewById(R.id.imageView);
                convertView.setTag(imageView);
                // 重置ImageView宽高
//                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(columnWidth, columnWidth);
//                imageView.setLayoutParams(params);
            } else {
                imageView = (ImageView) convertView.getTag();
            }

            if (position == listUrls.size()) {
                imageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.icon_addpic_unfocused));
                if (position == 1) {
                    imageView.setVisibility(View.GONE);
                }
            } else {
                Glide.with(mContext)
                        .load(new File(getItem(position)))
                        .placeholder(R.mipmap.default_error)
                        .error(R.mipmap.default_error)
                        .centerCrop()
                        .crossFade()
                        .into(imageView);
            }
            return convertView;
        }
    }


}
